import acount.Admin;
import acount.Login;
import acount.Normal;
import acount.User;
import book.Booklist;

import java.util.Scanner;

public class Main {

    public static User use(int c) {
        if (c == 1) {
            return new Admin();
        } else  {
            return new Normal();
        }
    }
    public static boolean login() {

        System.out.print("请输入用户名：");
        Scanner scan = new Scanner(System.in);
        String username = scan.nextLine();
        while(Login.checkUsername(User.getPos(username))) {
            username = scan.nextLine();
        }

        System.out.print("请输入密码：");
        String password = scan.nextLine();
        while(Login.checkPassword(User.getPass(password))) {
            password = scan.nextLine();
        }

        return true;
    }
    public static void main(String[] args) {


        /**
         * 实例化（初始化）书单
         */
        Booklist booklist = new Booklist();

        /**
         * 选择身份 选择好了后进入登录程序
         */
        System.out.println("1->管理员    0->访客");
        System.out.print("请选择身份：");
        int choice = 0;
        Scanner scan = new Scanner(System.in);
        choice = scan.nextInt();

        while(choice != 0 && choice != 1) {
            System.out.println("请重新输入，在0和1中选择！");
            choice = scan.nextInt();
        }

        /**
         *登录程序
         */
        login();

        User user = use(choice);

        int i = 0;
        while(true) {
            user.menu();
            i = scan.nextInt();

            user.operate(i,booklist);

        }
    }
}
